package ioc

import (
	"go.uber.org/zap"
	"goshell.straysh.com/internal/conf"
	"sync"
)

var ioc *IOC
var iocOnce = sync.Once{}

type Option func(c *IOC)

type IOC struct {
	logger *zap.Logger
	config *conf.Bootstrap
}

func New(opts ...Option) *IOC {
	iocOnce.Do(func() {
		ioc = &IOC{}
		for _, o := range opts {
			o(ioc)
		}
	})
	return ioc
}

func WithLogger(logger *zap.Logger) Option {
	return func(ioc *IOC) {
		ioc.logger = logger
	}
}

func WithConfig(config *conf.Bootstrap) Option {
	return func(ioc *IOC) {
		ioc.config = config
	}
}

func Ioc() *IOC {
	return ioc
}

func Logger() *zap.Logger {
	return ioc.logger
}

func Config() *conf.Bootstrap {
	return ioc.config
}
